﻿@{
    ViewBag.Title = this.Context.Request.QueryString["title"];
    Layout = "~/Views/Shared/_PageLayout.cshtml";
}

@section scripts
{
    @Scripts.Render("~/Scripts/swfupload")
    <script type="text/javascript">

        //挂接ExtJS准备完毕事件
        Ext.onReady
        (
            function () {
                //初始化快速提示
                Ext.QuickTips.init();

                //设置状态保存提供者（当前设置为Cookie）
                Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider', { path: _StatePath }));

                //用于记录当前记录
                var _CurrentRecord = undefined;

                //用于记录当前文件记录
                var _CurrentFile = undefined;

                //用于记录当前文件图片集合
                var _CurrentFileImages = undefined;
                              

                //编辑界面
                var _CurrentFace = undefined;

               

                //创建数据存储对象
                var store = Ext.create
                (
                    'Ext.data.Store',
                    {
                        pageSize: 20,
                        autoSync: false,
                        autoLoad: false,
                        root: 'data',
                        remoteFilter: true,
                        remoteSort: true,
                        sorters: [{ property: 'LoginName', direction: 'ASC' }],
                        model: 'ActiveOperation',
                        listeners:
                        {
                            //处理数据加载事件
                            load: function (store, records, successful, eOpts) {
                                //获得当前选中行
                                var models = grid.getSelectionModel().getSelection();

                                //判断是否选中数据
                                if (models.length > 0) {
                                    //设置当前选中记录
                                    _CurrentRecord = store.getById(models[0].getId());
                                }
                                else {
                                    //设置当前选中记录
                                    _CurrentRecord = null;
                                }

                                //更新按钮状态
                                UpdateButtonState(_CurrentRecord);
                            }
                        },
                        proxy:
                        {
                            type: 'ajax',
                            batchActions: false,
                            url: spms.url.Action('List', 'ActiveOperation'),
                            reader:
                            {
                                type: 'json',
                                root: 'data'
                            },
                            listeners:
                            {
                                //处理代理异常
                                exception: spms.exception.HandleProxyError
                            }
                        }
                    }
                );

                //创建角色数据存储对象
                var role_store = Ext.create
                (
                    'Ext.data.Store',
                    {
                        pageSize: 0,
                        autoSync: false,
                        autoLoad: false,
                        root: 'data',
                        remoteFilter: true,
                        remoteSort: false,
                        sorters: [{ property: 'Role_Title', direction: 'ASC' }],
                        model: 'Role',
                        proxy:
                        {
                            type: 'ajax',
                            batchActions: false,
                            url: spms.url.Action('UserRoles', 'Account'),
                            reader:
                            {
                                type: 'json',
                                root: 'data'
                            },
                            listeners:
                            {
                                //处理代理异常
                                exception: spms.exception.HandleProxyError
                            }
                        }
                    }
                );

                //创建工具栏
                var toolbar = Ext.create
                (
                    'Ext.toolbar.Toolbar',
                    {
                        region: 'north',
                        layout: 'hbox',
                        border: 5,
                        height: 32,
                        border: '1 0 1 0',
                        margins: '0 0 0 0',
                        padding: '0 6 0 6',
                        items:
                        [
                            {
                                id: 'spms-cmd-refresh',
                                text: '刷新',
                                tooltip: '重新加载数据',
                                tooltipType: 'qtip',
                                iconCls: 'spms-icon-refresh',
                                cls: 'spms-page-menu-button',
                                listeners:
                                {
                                    click: OnRefresh
                                }
                            },
                            '-',
                            {
                                id: 'spms-cmd-add',
                                text: '新增',
                                tooltip: '新增账户',
                                tooltipType: 'qtip',
                                cls: 'spms-page-menu-button',
                                iconCls: 'spms-icon-add',
                                listeners:
                                {
                                    click: OnAdd
                                }
                            },
                            {
                                id: 'spms-cmd-remove',
                                text: '删除',
                                tooltip: '删除选中的账户',
                                tooltipType: 'qtip',
                                cls: 'spms-page-menu-button',
                                iconCls: 'spms-icon-delete',
                                disabled: true,
                                listeners:
                                {
                                    click: OnRemove
                                }
                            },
                            {
                                id: 'spms-cmd-edit',
                                text: '编辑',
                                tooltip: '编辑选中的账户',
                                tooltipType: 'qtip',
                                cls: 'spms-page-menu-button',
                                iconCls: 'spms-icon-edit',
                                disabled: true,
                                listeners:
                                {
                                    click: OnEdit
                                }
                            }
                        ]
                    }
                );

                //创建检索面板
                var search = Ext.create
                (
                    'Ext.panel.Panel',
                    {
                        region: 'north',
                        frame: false,
                        animCollapse: false,
                        iconCls: 'spms-icon-search',
                        stateful: true,
                        stateId: 'spms-account-search-state',
                        collapsible: true,
                        collapseMode: 'header',
                        titleCollapse: true,
                        collapsed: true,
                        margin: '0 0 6 0',
                        layout: 'fit',
                        id: 'spms-panel-search',
                        cls: 'spms-page-card-detail',
                        border: true,
                        title: '检索',
                        listeners:
                        {
                            //挂接显示事件
                            show: function (win, options) {
                                //获得表单
                                var form = win.down('form');

                                //判断是否存在
                                if (form) {
                                    //重置内容
                                    form.getForm().reset();

                                    //设置焦点
                                    form.down('field').focus(false, 50);
                                }
                            }
                        },
                        items:
                        [
                            {
                                xtype: 'form',
                                frame: false,
                                autoScroll: true,
                                bodyPadding: 6,
                                bodyCls: 'spms-page-card-detail-form-body',
                                bodyBorder: false,
                                border: false,
                                layout:
                                {
                                    type: 'table',
                                    columns: 2,
                                    tableAttrs:
                                    {
                                        style:
                                        {
                                            width: '100%'
                                        },
                                        cellpadding: 6
                                    }
                                },
                                items:
                                [
                                    {
                                        xtype: 'fieldcontainer',
                                        width: '100%',
                                        defaultType: 'textfield',
                                        layout:
                                        {
                                            type: 'hbox',
                                            align: 'stretch'
                                        },
                                        padding: 0,
                                        border: 0,
                                        items:
                                        [
                                            {
                                                fieldLabel: '',
                                                minWidth: 80,
                                                maxLength: 20,
                                                xtype: 'checkbox',
                                                boxLabel: '编号:',
                                                cls: 'spms-card-checkbox',
                                                boxLabelCls: 'spms-card-checkbox-boxlabel',
                                                itemId: 'chkOperation_Code',
                                                allowBlank: true,
                                                value: true,
                                                inputValue: true,
                                                listeners:
                                                {
                                                    change: spms.event.OnCheckBoxLabelChange
                                                }
                                            },
                                            {
                                                fieldLabel: '',
                                                itemId: 'Operation_Code',
                                                flex: 1
                                            }
                                        ]
                                    },
                                    {
                                        xtype: 'fieldcontainer',
                                        width: '100%',
                                        defaultType: 'textfield',
                                        layout:
                                        {
                                            type: 'hbox',
                                            align: 'stretch'
                                        },
                                        padding: 0,
                                        border: 0,
                                        items:
                                        [
                                            {
                                                fieldLabel: '',
                                                minWidth: 80,
                                                maxLength: 20,
                                                xtype: 'checkbox',
                                                boxLabel: '状态:',
                                                cls: 'spms-card-checkbox',
                                                boxLabelCls: 'spms-card-checkbox-boxlabel',
                                                itemId: 'chkStatus',
                                                allowBlank: true,
                                                value: true,
                                                inputValue: true,
                                                listeners:
                                                {
                                                    change: spms.event.OnCheckBoxLabelChange
                                                }
                                            },
                                            {
                                                fieldLabel: '',
                                                itemId: 'Status',
                                                flex: 1
                                            }
                                        ]
                                    }
                                ],
                                dockedItems:
                                [
                                    {
                                        xtype: 'toolbar',
                                        dock: 'bottom',
                                        ui: 'footer',
                                        cls: 'spms-page-card-toolbar',
                                        padding: '0 6 12 0',
                                        items:
                                        [
                                            '->',
                                            {
                                                text: '检索',
                                                xtype: 'button',
                                                cls: 'spms-page-card-detail-toolbar-button',
                                                handler: function () {
                                                    //获得当前对象
                                                    var me = this;

                                                    //获得表单对象
                                                    var form = me.up('form');

                                                    //检查数据是否合法
                                                    if (form.getForm().isValid()) {
                                                        //清除过滤条件
                                                        store.filters.clear();

                                                        //生成过滤条件
                                                        var filters = new Array();

                                                        //判断是否以账户名检索
                                                        if (form.down('#chkOperation_Code').getValue()) {
                                                            //添加检索条件
                                                            filters.push({ property: 'Operation_Code@C', value: form.down('#Operation_Code').getValue() });
                                                        }

                                                        //判断是否以职员名检索
                                                        if (form.down('#chkStatus').getValue()) {
                                                            //添加检索条件
                                                            filters.push({ property: 'Status@C', value: form.down('#Status').getValue() });
                                                        }
                                                        //刷新数据
                                                        Refresh({ filters: filters });
                                                    }
                                                }
                                            }
                                        ]
                                    }
                                ]
                            }
                        ]
                    }
                );

                //创建表格
                var grid = Ext.create
                (
                    'Ext.grid.Panel',
                    {
                        region: 'center',
                        store: store,
                        stateful: true,
                        border: true,
                        cls: 'spms-grid',
                        stateId: 'spms-account-grid-state',
                        id: 'spms-card-grid',
                        forceFit: true,
                        autoScroll: true,
                        columnLines: true,
                        enableLocking: true,
                        unlockText: spms.resources.text_grid_column_unlock,
                        lockText: spms.resources.text_grid_column_lock,
                        viewConfig:
                        {
                            stripeRows: true,
                            loadingText: spms.resources.text_loading,
                            singleSelect: true
                        },
                        bbar: Ext.create
                            (
                            'SPMS.PagingToolbar',
                            {
                                store: store
                            }
                        ),
                        listeners:
                        {
                            select: OnRowSelect
                        },
                        columns:
                        [
                            {
                                text: '编号',
                                width: 100,
                                minWidth: 120,
                                sortable: true,
                                align: 'left',
                                dataIndex: 'Operation_Code',
                                hideable: false,
                                lockable: true
                            },
                            {
                                text: '作业类型',
                                width: 60,
                                minWidth: 80,
                                sortable: true,
                                align: 'center',
                                dataIndex: ' OperationType_ID',
                                hideable: true
                            },
                            {
                                text: '企业名称',
                                width: 140,
                                minWidth: 80,
                                sortable: true,
                                align: 'center',
                                dataIndex: 'CompanyName',
                                hideable: true
                            },
                            {
                                text: '法人',
                                width: 80,
                                minWidth: 80,
                                sortable: true,
                                align: 'center',
                                dataIndex: 'ContactPerson',
                                hideable: true
                            },

                            {
                                text: '状态',
                                width: 80,
                                minWidth: 80,
                                sortable: true,
                                align: 'center',
                                dataIndex: 'Status',
                                hideable: true
                            },
                            {
                                text: '联系电话1',
                                width: 120,
                                minWidth: 120,
                                sortable: false,
                                align: 'left',
                                dataIndex: 'ContactNumber1',
                                hideable: true
                            },
                            {
                                text: '联系电话2',
                                width: 120,
                                minWidth: 120,
                                sortable: false,
                                align: 'left',
                                dataIndex: 'ContactNumber2',
                                hideable: true
                            },
                            {
                                text: '电子邮箱',
                                width: 240,
                                minWidth: 120,
                                sortable: false,
                                align: 'left',
                                dataIndex: 'ContactEmail',
                                hideable: true
                            },
                            {
                                text: '备注',
                                width: 140,
                                minWidth: 240,
                                sortable: false,
                                align: 'left',
                                dataIndex: 'Memo',
                                hideable: true,
                                flex: 1
                            }
                        ]
                    }
                );

                //创建布局
                var card = Ext.create
                (
                    'Ext.panel.Panel',
                    {
                        region: 'center',
                        layout: 'card',
                        border: false,
                        defaults:
                        {
                            border: false
                        },
                        bodyStyle: 'padding:12px',
                        items:
                        [
                            {
                                xtype: 'panel',
                                id: 'spms-card-list',
                                layout: 'border',
                                items:
                                [
                                    search,
                                    grid
                                ]
                            }
                        ]
                    }
                );

                //创建视口
                var viewport = Ext.create
                (
                    'Ext.container.Viewport',
                    {
                        layout: 'border',
                        items:
                        [
                            {
                                region: 'north',
                                contentEl: 'spms-page-title',
                                border: false,
                                height: 48,
                                margins: '0 0 0 0'
                            },
                            toolbar,
                            card
                        ]
                    }
                );

                //加载数据
                store.load();

                //更新按钮状态

                function UpdateButtonState(record) {
                    //判断是否选中记录
                    if (record) {
                        //设置删除按钮状态
                        spms.common.SetDisabled('spms-cmd-remove', record.get('IsBuildin'));
                        //设置编辑按钮状态
                        spms.common.SetEnabled('spms-cmd-edit', true);
                        //设置授权按钮状态
                        spms.common.SetEnabled('spms-cmd-authorize', true);
                        //设置停用按钮状态
                        spms.common.SetEnabled('spms-cmd-state', true);
                        spms.common.ApplyIIf('spms-cmd-state', record.get('IsEnabled'), { text: '停用', tooltip: '停用选中的账户', iconCls: 'spms-icon-disabled' }, { text: '启用', tooltip: '启用选中的账户', iconCls: 'spms-icon-enabled' });
                        //设置解锁按钮状态
                        spms.common.SetEnabled('spms-cmd-unlock', record.get('IsLocked'));
                        //设置重置密码按钮状态
                        spms.common.SetEnabled('spms-cmd-resetpassword', true);
                    }
                    else {
                        //设置删除按钮状态
                        spms.common.SetEnabled('spms-cmd-remove', false);
                        //设置编辑按钮状态
                        spms.common.SetEnabled('spms-cmd-edit', true);
                        //设置授权按钮状态
                        spms.common.SetEnabled('spms-cmd-authorize', false);
                        //设置停用按钮状态
                        spms.common.SetEnabled('spms-cmd-state', false);
                        //设置解锁按钮状态
                        spms.common.SetEnabled('spms-cmd-unlock', false);
                        //设置重置密码按钮状态
                        spms.common.SetEnabled('spms-cmd-resetpassword', false);
                    }
                }

                //处理刷新按钮点击事件
                function OnRefresh(sender) {
                    //刷新数据
                    Refresh();
                }

                //处理新增按钮点击事件
                function OnAdd(sender) {
                    //获得当前对象
                    var me = this;

                    //判断窗体是否已经初始化
                    if (typeof me._Panel_Create == 'undefined') {

                        
                        //创建必要文件存储                       
                        me._FileFirstList = Ext.create
                        (
                            'Ext.data.Store',
                            {
                                pageSize: 0,
                                autoSync: false,
                                autoLoad: true,
                                root: 'data',
                                remoteFilter: true,
                                remoteSort: false,
                                filters: [{ property: 'Validity@E', value: 0 }],
                                sorters: [{ property: 'FileType_Name', direction: 'ASC' }],
                                model: 'FileType',
                                proxy:
                                {
                                    type: 'ajax',
                                    batchActions: false,
                                    url: spms.url.Action('List', 'FileType'),
                                    
                                    reader:
                                    {
                                        type: 'json',
                                        root: 'data'
                                    },
                                    listeners:
                                    {
                                        //处理代理异常
                                        exception: spms.exception.HandleProxyError
                                    }
                                }
                            }
                        );

                        //创建辅助文件存储  
                        me._FileSecondList = Ext.create
                        (
                            'Ext.data.Store',
                            {
                                pageSize: 0,
                                autoSync: false,
                                autoLoad: true,
                                root: 'data',
                                remoteFilter: true,
                                remoteSort: false,
                                filters: [{ property: 'Validity@E', value: 1 }],
                                sorters: [{ property: 'FileType_Name', direction: 'ASC' }],
                                model: 'FileType',
                                proxy:
                                {
                                    type: 'ajax',
                                    batchActions: false,
                                    url: spms.url.Action('List', 'FileType'),                                    
                                    reader:
                                    {
                                        type: 'json',
                                        root: 'data'
                                    },
                                    listeners:
                                    {
                                        //处理代理异常
                                        exception: spms.exception.HandleProxyError
                                    }
                                }
                            }
                        );

                      
                        //创建新增面板
                        me._Panel_Create = Ext.create
                        (
                            'Ext.panel.Panel',
                            {
                                layout: 'border',
                                id: 'spms-card-create',
                                cls: 'spms-page-card-detail',
                                border: false,
                                header:
                                {
                                    title: '作业登记',
                                    border: false,
                                    height: 36,
                                    cls: 'spms-page-card-detail-header'
                                },
                                listeners:
                                {
                                    //挂接显示事件
                                    show: function (win, options) {
                                        //获得表单
                                        var form = win.down('form');

                                        //判断是否存在
                                        if (form) {
                                            //获得窗体
                                            form.getForm().reset();

                                            //设置焦点
                                            form.down('field').focus(false, 50);
                                        }
                                    }
                                },
                                items:
                                [
                                    {
                                        xtype: 'form',
                                        region: 'center',
                                        autoScroll: true,
                                        frame: false,
                                        method: 'POST',
                                        waitMsgTarget: true,
                                        waitTitle: spms.resources.text_app_title,
                                        bodyPadding: 12,
                                        bodyCls: 'spms-page-card-detail-form-body',
                                        bodyBorder: false,
                                        border: false,
                                        defaultType: 'textfield',
                                        fieldDefaults:
                                        {
                                            labelAlign: 'left',
                                            labelWidth: 72,
                                            anchor: '100%',
                                            msgTarget: 'qtip'

                                        },
                                        layout:
                                        {
                                            type: 'table',
                                            columns: 2,
                                            tableAttrs:
                                            {
                                                style:
                                                {
                                                    width: '100%'
                                                },
                                                cellpadding: 6
                                            }
                                        },
                                        items:
                                        [
                                            {
                                                xtype: 'textfield',
                                                width: '90%',
                                                name: 'CompanyName',
                                                maxLength: 40,
                                                minLength: 4,
                                                minWidth: 120,
                                                fieldLabel: '企业名称',
                                                emptyText: '企业名称',
                                                allowBlank: false,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'ContactPerson',
                                                width: '90%',
                                                fieldLabel: '企业法人',
                                                emptyText: '企业法人',
                                                allowBlank: false,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'fieldcontainer',
                                                width: '100%',
                                                defaultType: 'textfield',
                                                layout:
                                                {
                                                    type: 'hbox',
                                                    align: 'stretch'
                                                },
                                                padding: 0,
                                                border: 0,
                                                items:
                                                [
                                                   
                                                     {
                                                         xtype: 'textfield',
                                                         name: 'ContactNumber1',
                                                         maxLength: 20,
                                                         width: '70%',
                                                         cls: 'Test',
                                                         fieldLabel: '客户电话1',
                                                         emptyText: '客户电话1',
                                                         allowBlank: true,
                                                         disabled: false
                                                     },
                                                     {
                                                         xtype: 'checkbox',
                                                         name: 'IsSendInfo1',                                                         
                                                         fieldLabel: '短信',                                                         
                                                         checked: true,
                                                         disabled: false,
                                                         inputValue: true
                                                     }
                                                ]
                                            },
                                            {
                                                xtype: 'fieldcontainer',
                                                width: '100%',
                                                defaultType: 'textfield',
                                                layout:
                                                {
                                                    type: 'hbox',
                                                    align: 'stretch'
                                                },
                                                padding: 0,
                                                border: 0,
                                                items:
                                                [
                                                    
                                                     {
                                                         xtype: 'textfield',
                                                         name: 'ContactNumber2',
                                                         maxLength: 20,
                                                         width: '70%',
                                                         cls: 'Test',
                                                         fieldLabel: '客户电话2',
                                                         emptyText: '客户电话2',
                                                         allowBlank: true,
                                                         disabled: false
                                                     },
                                                     {
                                                         xtype: 'checkbox',
                                                         name: 'IsSendInfo2',                                                         
                                                         fieldLabel: '短信',
                                                         checked: true,
                                                         disabled: false,
                                                         inputValue: true
                                                     }
                                                ]
                                            },
                                           
                                            {
                                                xtype: 'textfield',
                                                name: 'ContactEmail',
                                                maxLength: 20,
                                                width: '90%',
                                                cls: 'Test',
                                                fieldLabel: '客户邮箱',
                                                emptyText: '客户邮箱',
                                                allowBlank: true,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'Operation_Code',
                                                maxLength: 20,
                                                columns:2,
                                                width: '90%',
                                                cls: 'Test',
                                                fieldLabel: '作业编号',
                                                emptyText: '作业编号',
                                                allowBlank: true,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'RegAddress',
                                                maxLength: 20,
                                                width: '90%',
                                                cls: 'Test',
                                                fieldLabel: '注册地址',
                                                emptyText: '注册地址',
                                                allowBlank: true,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'YeZhiCode',
                                                maxLength: 20,
                                                width: '90%',
                                                cls: 'Test',
                                                fieldLabel: '营业执照编号',
                                                emptyText: '营业执照编号',
                                                allowBlank: true,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'OrgCode',
                                                maxLength: 20,
                                                width: '90%',
                                                cls: 'Test',
                                                fieldLabel: '组织机构代码',
                                                emptyText: '组织机构代码',
                                                allowBlank: true,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'ShiWCode',
                                                maxLength: 20,
                                                width: '90%',
                                                cls: 'Test',
                                                fieldLabel: '税务登记证编号',
                                                emptyText: '税务登记证编号',
                                                allowBlank: true,
                                                disabled: false
                                            }
                                            ,
                                            {
                                                xtype: 'fieldcontainer',
                                                fieldLabel: '必须材料',
                                                width: '100%',
                                                defaultType: 'textfield',
                                                layout: 'fit',
                                                padding: 0,
                                                border: 0,
                                                items:
                                                [
                                                    {
                                                        xtype: 'grid',
                                                        height: 240,
                                                        store: me._FileFirstList,
                                                        draggable: false,
                                                        stateful: false,
                                                        cls: 'spms-grid',
                                                        border: true,
                                                        forceFit: true,
                                                        autoScroll: true,
                                                        columnLines: true,
                                                        viewConfig:
                                                        {
                                                            stripeRows: true,
                                                            loadingText: spms.resources.text_loading,
                                                            singleSelect: true
                                                        },
                                                        listeners:
                                                        {
                                                            select: OnRowSelectFile
                                                        },
                                                        columns:
                                                        [
                                                            {
                                                                text: '选择',
                                                                width: 80,
                                                                minWidth: 80,
                                                                sortable: true,
                                                                xtype: 'checkcolumn',
                                                                dataIndex: 'IsAssigned',
                                                                hideable: false,
                                                                align: 'center'
                                                            },
                                                            {
                                                                text: '资料名称',
                                                                width: 200,
                                                                minWidth: 120,
                                                                sortable: true,
                                                                align: 'left',
                                                                dataIndex: 'FileType_Name',
                                                                hideable: false
                                                            }
                                                        ]
                                                    }
                                                ]
                                            },
                                            {
                                                xtype: 'fieldcontainer',
                                                fieldLabel: '辅助材料',
                                                width: '100%',
                                                defaultType: 'textfield',
                                                layout: 'fit',
                                                padding: 0,
                                                border: 0,
                                                items:
                                                [
                                                    {
                                                        xtype: 'grid',
                                                        height: 240,
                                                        store: me._FileSecondList,
                                                        draggable: false,
                                                        stateful: false,
                                                        cls: 'spms-grid',
                                                        border: true,
                                                        forceFit: true,
                                                        autoScroll: true,
                                                        columnLines: true,
                                                        viewConfig:
                                                        {
                                                            stripeRows: true,
                                                            loadingText: spms.resources.text_loading,
                                                            singleSelect: true
                                                        },
                                                        listeners:
                                                        {
                                                            select: OnRowSelectFile
                                                        },
                                                        columns:
                                                        [
                                                            {
                                                                text: '选择',
                                                                width: 80,
                                                                minWidth: 80,
                                                                sortable: true,
                                                                xtype: 'checkcolumn',
                                                                dataIndex: 'IsAssigned',
                                                                hideable: false,
                                                                align: 'center'
                                                            },
                                                            {
                                                                text: '资料名称',
                                                                width: 200,
                                                                minWidth: 120,
                                                                sortable: true,
                                                                align: 'left',
                                                                dataIndex: 'FileType_Name',
                                                                hideable: false
                                                            }
                                                        ]
                                                    }
                                                ]
                                            },
                                            {
                                                xtype: 'grid',
                                                name: 'gridImages',
                                                itemId: 'gridImages',
                                                height: 240,
                                                store: _CurrentFileImages,
                                                draggable: false,
                                                stateful: false,
                                                cls: 'spms-grid',
                                                border: true,
                                                forceFit: true,
                                                autoScroll: true,
                                                columnLines: true,
                                                viewConfig:
                                                {
                                                    stripeRows: true,
                                                    loadingText: spms.resources.text_loading,
                                                    singleSelect: true
                                                },
                                                bbar:
                                                [
                                                    {
                                                        xtype: 'button',
                                                        text: '添加附加图片',
                                                        cls: 'spms-page-menu-button',
                                                        iconCls: 'spms-icon-add',
                                                        handler: OnAppendImage
                                                    }
                                                ],
                                                listeners:
                                                {
                                                    select: OnRowSelect                                                    
                                                },
                                                columns:
                                                [
                                                    {
                                                        xtype: 'actioncolumn',
                                                        menuDisabled: true,
                                                        text: '操作',
                                                        align: 'center',
                                                        sortable: false,
                                                        hideable: false,
                                                        padding: 0,
                                                        width: 80,
                                                        minWidth: 80,
                                                        items:
                                                        [
                                                            {
                                                                iconCls: 'spms-icon-view',
                                                                tooltip: '查看图片',
                                                                handler: OnViewImage
                                                            },
                                                            {
                                                                iconCls: 'spms-icon-upload',
                                                                tooltip: '上传图片',
                                                                handler: OnUploadImage
                                                            },
                                                            {
                                                                iconCls: 'spms-icon-row-delete',
                                                                tooltip: '删除图片',
                                                                handler: OnDeleteImage
                                                            }
                                                        ]
                                                    },
                                                    {
                                                        text: '编号',
                                                        width: 100,
                                                        minWidth: 120,
                                                        sortable: true,
                                                        align: 'left',
                                                        dataIndex: 'File_Order',
                                                        hideable: false,
                                                        lockable: true
                                                    }
                                                  
                                                ]
                                            }
                                            
                                            
                                        ],
                                        dockedItems:
                                        [
                                            {
                                                xtype: 'toolbar',
                                                dock: 'bottom',
                                                ui: 'footer',
                                                cls: 'spms-page-card-detail-toolbar',
                                                padding: '15 0 3 0',
                                                items:
                                                [
                                                    '->',
                                                    {
                                                        text: '连续新增',
                                                        xtype: 'button',
                                                        cls: 'spms-page-card-detail-toolbar-button',
                                                        handler: function () {
                                                            //执行新增操作
                                                            DoAdd.call(me, true);
                                                        }
                                                    },

                                                    {
                                                        text: '新增',
                                                        xtype: 'button',
                                                        cls: 'spms-page-card-detail-toolbar-button',
                                                        handler: function () {
                                                            //执行新增操作
                                                            DoAdd.call(me, false);
                                                        }
                                                    },
                                                    {
                                                        text: '取消',
                                                        xtype: 'button',
                                                        cls: 'spms-page-card-detail-toolbar-button',
                                                        handler: function () {
                                                            //启用工具栏
                                                            toolbar.setDisabled(false);

                                                            //返回一览标签
                                                            card.getLayout().setActiveItem('spms-card-list');
                                                        }
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ]
                            }
                        );
                        //添加到面板
                        card.add(me._Panel_Create);
                        
                    }

                    //禁用工具栏
                    toolbar.setDisabled(true);

                    //切换到面板
                    card.getLayout().setActiveItem('spms-card-create');
                }

                //处理删除按钮点击事件
                function OnRemove(sender) {
                    //判断是否选中记录
                    if (!spms.common.IsValid(_CurrentRecord)) {
                        return;
                    }

                    //询问是否确定删除
                    Ext.Msg.show
                    (
                        {
                            title: spms.resources.text_app_title,
                            msg: '确定要删除选中的账户"' + _CurrentRecord.get('LoginName') + '"吗?',
                            buttons: Ext.Msg.YESNO,
                            icon: Ext.Msg.QUESTION,
                            autoScroll: true,
                            closeAction: 'destroy',
                            fn: function (button, text, eOpts) {
                                //判断是否确定删除 
                                if (button == 'yes') {
                                    //创建请求对象
                                    Ext.Ajax.request
                                    (
                                        {
                                            url: spms.url.Action('Delete', 'Account'),
                                            method: spms.constant.HttpMethod.POST,
                                            jsonData: _CurrentRecord.data,
                                            callback: function (options, success, response) {
                                                //处理错误
                                                if (spms.exception.HandleAjaxRequestError(options, success, response)) {
                                                    //刷新数据
                                                    Refresh();
                                                }
                                            }
                                        }
                                    );
                                }
                            }
                        }
                    );
                }

                //处理编辑按钮点击事件
                function OnEdit(sender) {
                    //判断是否选中记录
                    if (!spms.common.IsValid(_CurrentRecord)) {
                        //如果没有选中记录，则直接返回
                        return;
                    }

                    //获得当前对象
                    var me = this;

                    //判断窗体是否已经初始化
                    if (typeof me._Panel_Edit == 'undefined') {
                        //创建新增面板
                        me._Panel_Edit = Ext.create
                        (
                            'Ext.panel.Panel',
                            {
                                layout: 'fit',
                                id: 'spms-card-edit',
                                cls: 'spms-page-card-detail',
                                border: false,
                                header:
                                {
                                    title: '编辑账户',
                                    border: false,
                                    height: 36,
                                    cls: 'spms-page-card-detail-header'
                                },
                                listeners:
                                {
                                    //挂接显示事件
                                    show: function (panel, options) {
                                        //获得面板
                                        var panel = me._Panel_Edit;

                                        //获得表单
                                        var form = panel.down('form');

                                        //获得预览面板
                                        var panelSignaturePreview = panel.down('#SignaturePreview');

                                        //判断是否存在
                                        if (spms.common.IsValid(form)) {
                                            //重置内容
                                            form.getForm().reset();

                                            //判断是否有效
                                            if (spms.common.IsValid(panelSignaturePreview)) {
                                                //显示预览图
                                                panelSignaturePreview.setSrc(Ext.BLANK_IMAGE_URL);
                                            }

                                            //提交数据
                                            form.load
                                            (
                                                {
                                                    url: spms.url.Action('Detail', 'Account'),
                                                    method: spms.constant.HttpMethod.Get,
                                                    params: { User_ID: _CurrentRecord.get('Operation_Code'), LoginName: _CurrentRecord.get('OperationType_ID') },
                                                    waitTitle: spms.resources.text_loading_title,
                                                    waitMsg: spms.resources.text_loading,
                                                    success: function (panel, action) {
                                                        //处理错误
                                                        if (spms.exception.HandleSuccessError(panel, action)) {
                                                            //判断是否有预览图片
                                                            var txtHasSignature = form.down('#HasSignature');

                                                            //判断是否有效
                                                            if (spms.common.IsValid(txtHasSignature)) {
                                                                //判断是否有签名图
                                                                if (txtHasSignature.getValue() == 'true') {
                                                                    //用于保存参数
                                                                    var params =
                                                                    [
                                                                        { Name: 'User_ID', Value: _CurrentRecord.get('User_ID') }
                                                                    ];

                                                                    //获得图片地址
                                                                    var imageUrl = spms.url.Action('GetSignatureImage', 'Account', params);

                                                                    //显示预览图
                                                                    panelSignaturePreview.setSrc(imageUrl);
                                                                }
                                                            }

                                                            //设置焦点
                                                            form.down('field').focus(false, 100);
                                                        }
                                                        else {
                                                            //启用工具栏
                                                            toolbar.setDisabled(false);

                                                            //返回一览标签
                                                            card.getLayout().setActiveItem('spms-card-list');
                                                        }
                                                    },
                                                    failure: function (form, action) {
                                                        //处理错误
                                                        spms.exception.HandleFailureError(form, action);

                                                        //启用工具栏
                                                        toolbar.setDisabled(false);

                                                        //返回一览标签
                                                        card.getLayout().setActiveItem('spms-card-list');
                                                    }
                                                }
                                            );
                                        }
                                    }
                                },
                                items:
                                [
                                    {
                                        xtype: 'form',
                                        autoScroll: true,
                                        frame: false,
                                        method: 'POST',
                                        waitMsgTarget: true,
                                        waitTitle: spms.resources.text_app_title,
                                        bodyPadding: 12,
                                        bodyCls: 'spms-page-card-detail-form-body',
                                        bodyBorder: false,
                                        border: false,
                                        defaultType: 'textfield',
                                        fieldDefaults:
                                        {
                                            labelAlign: 'left',
                                            labelWidth: 72,
                                            anchor: '100%',
                                            msgTarget: 'qtip'
                                        },
                                        layout:
                                        {
                                            type: 'table',
                                            columns: 2,
                                            tableAttrs:
                                            {
                                                style:
                                                {
                                                    width: '100%'
                                                },
                                                cellpadding: 6
                                            }
                                        },
                                        items:
                                        [
                                            {
                                                xtype: 'hiddenfield',
                                                name: 'User_ID'
                                            },
                                           {
                                               xtype: 'textfield',
                                               width: '90%',
                                               name: 'CompanyName',
                                               maxLength: 40,
                                               minLength: 4,
                                               minWidth: 120,
                                               cls: 'Test',
                                               fieldLabel: '企业名称',
                                               emptyText: '企业名称',
                                               allowBlank: false,
                                               disabled: false
                                           },
                                            {
                                                xtype: 'textfield',
                                                name: 'ContactPerson',
                                                width: '90%',
                                                cls: 'Test',
                                                fieldLabel: '企业法人',
                                                emptyText: '企业法人',
                                                allowBlank: false,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'IsSendInfo1',
                                                cls: 'Test',
                                                fieldLabel: '是否发送短信',
                                                emptyText: '是否发送短信',
                                                width: '90%',
                                                allowBlank: false,
                                                disabled: false
                                            },
                                            //{
                                            //    xtype: 'textfield',
                                            //    name: 'EmployeeName',
                                            //    maxLength: 40,
                                            //    width: '90%',
                                            //    fieldLabel: '是否发送短信',
                                            //    emptyText: '是否发送短信',
                                            //    allowBlank: true,
                                            //    disabled: false
                                            //},
                                            {
                                                xtype: 'fieldcontainer',
                                                width: '100%',
                                                defaultType: 'textfield',
                                                layout:
                                                {
                                                    type: 'hbox',
                                                    align: 'stretch'
                                                },
                                                padding: 0,
                                                border: 0,
                                                items:
                                                [
                                                    {
                                                        fieldLabel: '',
                                                        minWidth: 80,
                                                        maxLength: 20,
                                                        xtype: 'checkbox',
                                                        boxLabel: '客户电话1',
                                                        cls: 'spms-card-checkbox',
                                                        boxLabelCls: 'spms-card-checkbox-boxlabel',
                                                        itemId: 'chkContactNumber1',
                                                        allowBlank: true,
                                                        value: true,
                                                        inputValue: true,
                                                        listeners:
                                                        {
                                                            change: spms.event.OnCheckBoxLabelChange
                                                        }
                                                    },
                                                    {
                                                        fieldLabel: '',
                                                        itemId: 'ContactNumber1',
                                                        flex: 1
                                                    },
                                                ]
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'IsSendInfo2',
                                                maxLength: 20,
                                                width: '90%',
                                                fieldLabel: '是否发送短信',
                                                emptyText: '是否发送短信',
                                                allowBlank: true,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'ContactEmail',
                                                maxLength: 20,
                                                width: '90%',
                                                cls: 'Test',
                                                fieldLabel: '客户邮箱',
                                                emptyText: '客户邮箱',
                                                allowBlank: true,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'OperationType_ID',
                                                maxLength: 20,
                                                columns: 2,
                                                width: '90%',
                                                cls: 'Test',
                                                fieldLabel: '作业编号',
                                                emptyText: '作业编号',
                                                allowBlank: true,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'RegAddress',
                                                maxLength: 20,
                                                width: '90%',
                                                cls: 'Test',
                                                fieldLabel: '注册地址',
                                                emptyText: '注册地址',
                                                allowBlank: true,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'YeZhiCode',
                                                maxLength: 20,
                                                width: '90%',
                                                cls: 'Test',
                                                fieldLabel: '营业执照编号',
                                                emptyText: '营业执照编号',
                                                allowBlank: true,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'OrgCode',
                                                maxLength: 20,
                                                width: '90%',
                                                cls: 'Test',
                                                fieldLabel: '组织机构代码',
                                                emptyText: '组织机构代码',
                                                allowBlank: true,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'ShiWCode',
                                                maxLength: 20,
                                                width: '90%',
                                                cls: 'Test',
                                                fieldLabel: '税务登记证编号',
                                                emptyText: '税务登记证编号',
                                                allowBlank: true,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'hiddenfield',
                                                name: 'HasSignature',
                                                itemId: 'HasSignature'
                                            },
                                            {
                                                xtype: 'hiddenfield',
                                                name: 'Signature_ID',
                                                itemId: 'Signature_ID'
                                            }
                                        ],
                                        dockedItems:
                                        [
                                            {
                                                xtype: 'toolbar',
                                                dock: 'bottom',
                                                ui: 'footer',
                                                cls: 'spms-page-card-detail-toolbar',
                                                padding: '15 0 3 0',
                                                items:
                                                [
                                                    '->',
                                                    {
                                                        text: '保存',
                                                        xtype: 'button',
                                                        cls: 'spms-page-card-detail-toolbar-button',
                                                        handler: function () {
                                                            //获得表单
                                                            var form = me._Panel_Edit.down('form');

                                                            //获得存储对象
                                                            var roleStore = role_store;

                                                            //用于记录需要提交的数据
                                                            var postParams = [];

                                                            //循环收集需要提交的数据
                                                            for (var index = 0; index < roleStore.getCount() ; index++) {
                                                                //获得记录
                                                                var model = roleStore.getAt(index);

                                                                //判断是否设置了权限
                                                                if (model.get('IsAssigned')) {
                                                                    //添加模型
                                                                    postParams.push(model.get('Role_ID'));
                                                                }
                                                            }

                                                            //判断表单是否有效
                                                            if (form) {
                                                                //获得表单对象
                                                                var formBase = form.getForm();

                                                                //检查数据是否合法
                                                                if (formBase.isValid()) {
                                                                    //提交数据
                                                                    formBase.submit
                                                                    (
                                                                        {
                                                                            url: spms.url.Action('Update', 'Account'),
                                                                            method: spms.constant.HttpMethod.Post,
                                                                            params: { Roles: postParams },
                                                                            submitEmptyText: false,
                                                                            waitTitle: spms.resources.text_submitting_title,
                                                                            waitMsg: spms.resources.text_submitting,
                                                                            success: function (panel, action) {
                                                                                //处理提交错误
                                                                                if (spms.exception.HandleSuccessError(panel, action)) {
                                                                                    //启用工具栏
                                                                                    toolbar.setDisabled(false);

                                                                                    //返回一览标签
                                                                                    card.getLayout().setActiveItem('spms-card-list');

                                                                                    //刷新数据
                                                                                    Refresh();
                                                                                }
                                                                            },
                                                                            failure: spms.exception.HandleFailureError
                                                                        }
                                                                    );
                                                                }
                                                            }
                                                        }
                                                    },
                                                    {
                                                        text: '取消',
                                                        xtype: 'button',
                                                        cls: 'spms-page-card-detail-toolbar-button',
                                                        handler: function () {
                                                            //启用工具栏
                                                            toolbar.setDisabled(false);

                                                            //返回一览标签
                                                            card.getLayout().setActiveItem('spms-card-list');
                                                        }
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ]
                            }
                        );

                        //添加到面板
                        card.add(me._Panel_Edit);
                    }

                    //禁用工具栏
                    toolbar.setDisabled(true);

                    //切换到面板
                    card.getLayout().setActiveItem('spms-card-edit');

                    //加载数据
                    role_store.load({ params: { 'userID': _CurrentRecord.get('Operation_Code') } });
                }

                //处理授权按钮点击事件
                function OnAuthorize(sender) {
                    //判断是否选中记录
                    if (!spms.common.IsValid(_CurrentRecord)) {
                        return;
                    }

                    //获得当前对象
                    var me = this;

                    //判断窗体是否已经初始化
                    if (typeof me._Panel_Authorize == 'undefined') {
                        //创建新增面板
                        me._Panel_Authorize = Ext.create
                        (
                            'Ext.panel.Panel',
                            {
                                layout: 'fit',
                                bodyPadding: '12 6 12 6',
                                id: 'spms-card-authorize',
                                cls: 'spms-page-card-detail',
                                bodyCls: 'spms-page-card-body',
                                border: false,
                                header:
                                {
                                    title: '账户授权',
                                    border: false,
                                    height: 36,
                                    cls: 'spms-page-card-detail-header'
                                },
                                dockedItems:
                                [
                                    {
                                        xtype: 'toolbar',
                                        dock: 'bottom',
                                        ui: 'footer',
                                        cls: 'spms-page-card-detail-toolbar',
                                        padding: '15 0 3 0',
                                        items:
                                        [
                                            '->',
                                            {
                                                text: '确定',
                                                xtype: 'button',
                                                cls: 'spms-page-card-detail-toolbar-button',
                                                handler: function () {
                                                    //用于记录需要提交的数据
                                                    var postParams = [];

                                                    //循环收集需要提交的数据
                                                    for (var index = 0; index < role_store.getCount() ; index++) {
                                                        //获得记录
                                                        var model = role_store.getAt(index);

                                                        //判断是否设置了权限
                                                        if (model.get('IsAssigned')) {
                                                            //添加模型
                                                            postParams.push(model.get('Role_ID'));
                                                        }
                                                    }

                                                    //创建要提交的数据
                                                    var jsonData = { User_ID: _CurrentRecord.get('User_ID'), Roles: postParams };

                                                    //创建请求对象
                                                    Ext.Ajax.request
                                                    (
                                                        {
                                                            url: spms.url.Action('Authorize', 'Account'),
                                                            method: spms.constant.HttpMethod.POST,
                                                            jsonData: jsonData,
                                                            callback: function (options, success, response) {
                                                                //处理错误
                                                                if (spms.exception.HandleAjaxRequestError(options, success, response)) {
                                                                    //启用工具栏
                                                                    toolbar.setDisabled(false);

                                                                    //返回一览标签
                                                                    card.getLayout().setActiveItem('spms-card-list');
                                                                }
                                                            }
                                                        }
                                                    );
                                                }
                                            },
                                            {
                                                text: '取消',
                                                xtype: 'button',
                                                cls: 'spms-page-card-detail-toolbar-button',
                                                handler: function () {
                                                    //启用工具栏
                                                    toolbar.setDisabled(false);

                                                    //返回一览标签
                                                    card.getLayout().setActiveItem('spms-card-list');
                                                }
                                            }
                                        ]
                                    }
                                ],
                                items:
                                [
                                    {
                                        xtype: 'grid',
                                        store: role_store,
                                        draggable: false,
                                        stateful: false,
                                        cls: 'spms-grid',
                                        border: true,
                                        forceFit: true,
                                        autoScroll: true,
                                        columnLines: true,
                                        viewConfig:
                                        {
                                            stripeRows: true,
                                            loadingText: spms.resources.text_loading,
                                            singleSelect: true
                                        },
                                        listeners:
                                        {
                                            select: OnRowSelect
                                        },
                                        columns:
                                        [
                                            {
                                                text: '授予状态',
                                                width: 80,
                                                minWidth: 80,
                                                sortable: true,
                                                xtype: 'checkcolumn',
                                                dataIndex: 'IsAssigned',
                                                hideable: false,
                                                align: 'center'
                                            },
                                            {
                                                text: '角色显示名',
                                                width: 200,
                                                minWidth: 120,
                                                sortable: true,
                                                align: 'left',
                                                dataIndex: 'Role_Title',
                                                hideable: false
                                            },
                                            {
                                                text: '角色参照名',
                                                width: 200,
                                                minWidth: 120,
                                                sortable: true,
                                                align: 'left',
                                                dataIndex: 'Role_Name',
                                                hideable: false
                                            },
                                            {
                                                text: '角色说明',
                                                width: 200,
                                                minWidth: 120,
                                                sortable: true,
                                                align: 'left',
                                                dataIndex: 'Role_Desc',
                                                hideable: false,
                                                flex: 1
                                            }
                                        ]
                                    }
                                ]
                            }
                        );

                        //添加到面板
                        card.add(me._Panel_Authorize);
                    }

                    //禁用工具栏
                    toolbar.setDisabled(true);

                    //切换到面板
                    card.getLayout().setActiveItem('spms-card-authorize');

                    //加载数据
                    role_store.load({ params: { 'userID': _CurrentRecord.get('User_ID') } });
                }

                //处理状态变更按钮点击事件
                function OnChangeState(sender) {
                    //判断是否选中记录
                    if (!spms.common.IsValid(_CurrentRecord)) {
                        return;
                    }

                    //用于保存提示消息
                    var msg = '';

                    //判断是否启用
                    if (_CurrentRecord.get('IsEnabled')) {
                        //设置提示信息
                        msg = msg.concat('确定要停用选中的账户"', _CurrentRecord.get('LoginName'), '"吗？<br\><br\>注意：账户一旦停用，则无法使用该账号登陆系统。')
                    }
                    else {
                        //设置提示信息
                        msg = msg.concat('确定要启用选中的账户"', _CurrentRecord.get('LoginName'), '"吗？<br\><br\>注意：账户一旦启用，则可以使用该账号登陆系统。')
                    }

                    //创建参数
                    var options =
                    {
                        msg: msg,
                        url: spms.url.Action('ChangeState', 'Account'),
                        params: _CurrentRecord.data,
                        callback: OnAjaxRequestCallback
                    }

                    //执行请求
                    spms.common.DoAjaxRequestWithConfirm(options);
                }

                //处理状解锁按钮点击事件
                function OnUnlock(sender) {
                    //判断是否选中记录
                    if (!spms.common.IsValid(_CurrentRecord)) {
                        return;
                    }

                    //创建参数
                    var options =
                    {
                        msg: ''.concat('确定要解除选中账户"', _CurrentRecord.get('LoginName'), '"的锁定状态吗？'),
                        url: spms.url.Action('Unlock', 'Account'),
                        params: _CurrentRecord.data,
                        callback: OnAjaxRequestCallback
                    }

                    //执行请求
                    spms.common.DoAjaxRequestWithConfirm(options);
                }

                //处理状解锁按钮点击事件
                function OnResetPassword(sender) {
                    //判断是否选中记录
                    if (!spms.common.IsValid(_CurrentRecord)) {
                        return;
                    }

                    //创建参数
                    var options =
                    {
                        msg: ''.concat('确定要重置选中账户"', _CurrentRecord.get('LoginName'), '"的登陆密码吗？<br\><br\>注意：账户的登陆密码一旦重置，则该账户下次登陆系统时必须修改登陆密码。'),
                        url: spms.url.Action('ResetPassword', 'Account'),
                        params: _CurrentRecord.data,
                        callback: OnAjaxRequestCallback
                    }

                    //执行请求
                    spms.common.DoAjaxRequestWithConfirm(options);
                }

                //Ajax回调
                function OnAjaxRequestCallback(options) {
                    //刷新数据
                    Refresh();
                }

                //刷新数据
                function Refresh(options) {
                    //刷新数据
                    store.load(options);
                }

                //处理表格行选中事件
                function OnRowSelect(panel, record, index, options) {
                    //记录当前选中记录
                    _CurrentRecord = record;

                    //更新按钮状态
                    UpdateButtonState(record);
                }

                //处理资料表格行选中事件
                function OnRowSelectFile(panel, record, index, options) {
                    //记录当前选中记录
                    _CurrentFile = record;
                    
                    if (_CurrentFile.get("Files") == undefined) {
                        _CurrentFile.set("Files", []);
                    }                    
                    //取出当前文件的资料集合
                    _CurrentFileImages = _CurrentFile.get("Files");

                    _Panel_Create = card.down('#spms-card-create');                   
                    if (typeof _Panel_Create != 'undefined') {
                        var grid = _Panel_Create.down('#gridImages');
                        var store = grid.getStore();
                        //判断是否有效
                        if (!spms.common.IsValid(store)) {
                            //直接返回
                            return;
                        }
                        store.loadData(_CurrentFileImages);

                    }

                    //更新按钮状态
                    //UpdateButtonState(record);
                }
                //处理上传图片事件
                function OnUploadImage(grid, rowIndex, colIndex) {
                    //获得存储对象
                    var store = grid.getStore();

                    ////判断是否有效
                    //if (!spms.common.IsValid(store)) {
                    //    //直接返回
                    //    return;
                    //}

                    //获得对应的记录
                    var record = store.getAt(rowIndex);

                    //判断是否有效
                    if (!spms.common.IsValid(record)) {
                        //直接返回
                        return;
                    }

                    //上传文件
                    spms.common.UploadFile
                    (
                        {
                            file_types: '*.bmp;*.png;*.jpg;*.jpeg;*.jpe;*.jfif;*.gif',
                            file_types_description: 'Image Files(*.bmp;*.png;*.jpg;*.jpeg;*.jpe;*.jfif;*.gif)',
                            file_size_limit: '2 MB',
                            file_size_limit_tip: '小于2MB的图片文件',
                            callback: OnUploadImageCallback,
                            title: '上传图片',
                            _record: record
                        }
                    );
                }

                //图片上传完成回调
                function OnUploadImageCallback(response, options) {
                    //判断是否成功
                    if (!response.success) {
                        //直接返回
                        return;
                    }

                    //获得记录
                    var record = options._record;

                    //获得上传文件编号
                    if (response.data && response.data.length > 0 && record) {
                        //获得文件编号
                        var tempFileID = response.data[0];

                        //更新记录
                        record.set('File_ID', tempFileID);
                        record.set('HasContent', true);
                        record.set('IsNew', true);
                    }
                }

               
                //执行新增图片操作
                function OnAppendImage(sender, eOpts) {
                    if (_CurrentFile == undefined)
                    {
                        alert("请选择一种材料");
                        return;
                    }
                    
                    //获得表格对象
                    var grid = sender.up( 'grid' );
                        //获得存储对象
                        var store = grid.getStore();
                        var count=store.getCount();
                        //判断是否有效
                        if (!spms.common.IsValid(store)) {
                            //直接返回
                            return;
                        }
                        //添加空白数据
                        store.add
                        (
                            Ext.create
                            (
                                'UploadFile',
                                {
                                    File_ID: spms.common.NewGuid(),
                                    File_Title: '封装图片',
                                    HasContent: false,
                                    IsNew: true,
                                    File_Order: count+1
                                }
                            )
                        );
                        //var item = Ext.create('UploadFile');
                        //item.File_ID = 12;
                        //var item1 = Ext.create('UploadFile');
                        //item1.File_ID = 12;
                        //var items = [];
                        //items.push(item);
                        //items.push(item1);
                        _CurrentFile.set("Files", grid.getStore().data.items);
                }
                //处理查看图片事件
                function OnViewImage(grid, rowIndex, colIndex) {
                    //获得存储对象
                    var store = grid.getStore();

                    //获得对应的记录
                    var record = store.getAt(rowIndex);

                    //判断记录是否存在
                    if (!spms.common.IsValid(record)) {
                        return;
                    }

                    //判断是否已经上传了图片
                    if (!record.get('HasContent')) {
                        //如果没有内容，则直接返回
                        return;
                    }

                    //用于保存参数
                    var params =
                    [
                        { Name: 'File_ID', Value: record.get('File_ID') },
                        { Name: 'IsNew', Value: record.get('IsNew') }
                    ];

                    //用于保存参数
                    var options =
                    {
                        url: spms.url.Action('GetImage', 'Packaging', params),
                        title: record.get('File_Title')
                    };

                    //显示预览
                    spms.common.Preview(options);
                }

                //处理删除图片事件
                function OnDeleteImage(grid, rowIndex, colIndex) {
                    //获得存储对象
                    var store = grid.getStore();

                    //获得对应的记录
                    var record = store.getAt(rowIndex);
                                       
                    //提示信息
                    Ext.MessageBox.show
                    (
                        {
                            title: spms.resources.text_app_title,
                            msg: '确定要删除名为\"' + record.get('File_Title') + '\"的图片吗？',
                            buttons: Ext.Msg.YESNO,
                            icon: Ext.Msg.QUESTION,
                            autoScroll: true,
                            closeAction: 'destroy',
                            fn: function (buttonId, text, eOpts) {
                                //判断是否安装
                                if (buttonId == 'yes') {
                                    //判断是否有效
                                    if (!spms.common.IsValid(store)) {
                                        //直接返回
                                        return;
                                    }

                                    //删除对应记录
                                    store.removeAt(rowIndex);
                                }
                            }
                        }
                    );
                }


                
                //执行新增操作
                function DoAdd(isContinuousNew) {
                    //获得当前对象
                    var me = this;

                    //获得表单
                    var form = me._Panel_Create.down('form');

                    //获得存储对象
                    var FileFirstList = me._FileFirstList;
                    var FileSecondList = me._FileSecondList;

                    //用于记录需要提交的数据
                    var postParamsFirst = [];
                    var postParamsSecond = [];

                    //循环收集需要提交的数据
                    for (var index = 0; index < FileFirstList.getCount() ; index++) {
                        //获得记录
                        var model = FileFirstList.getAt(index);                       

                        //判断是否设置了权限
                        if (model.get('IsAssigned')) {
                            var item = Ext.create('ActiveOperationFiles');
                            item.File_ID = model.get('FileType_ID');
                            item.FileType_ID = model.get('FileType_ID');
                            alert(item.FileType_ID);
                            //添加模型
                            postParamsFirst.push(item);
                        }
                    }
                    for (var index = 0; index < FileSecondList.getCount() ; index++) {
                        //获得记录
                        var model = FileSecondList.getAt(index);

                        //判断是否设置了权限
                        if (model.get('IsAssigned')) {
                            var item = Ext.create('ActiveOperationFiles');
                            item.File_ID = model.get('FileType_ID');
                            item.FileType_ID = model.get('FileType_ID');
                            alert(item.FileType_ID);
                            //添加模型
                            postParamsSecond.push(item);
                        }
                    }

                    

                    //判断表单是否有效
                    if (form) {
                        //获得表单对象
                        var formBase = form.getForm();

                        //检查数据是否合法
                        if (formBase.isValid()) {
                            //提交数据
                            formBase.submit
                            (
                                {
                                    url: spms.url.Action('Create', 'ActiveOperation'),
                                    method: spms.constant.HttpMethod.Post,
                                    params: { FileFirstList: JSON.stringify(postParamsFirst), FileSecondList: JSON.stringify(postParamsSecond) },
                                    submitEmptyText: false,
                                    waitTitle: spms.resources.text_submitting_title,
                                    waitMsg: spms.resources.text_submitting,
                                    success: function (panel, action) {
                                        //处理提交错误
                                        if (spms.exception.HandleSuccessError(panel, action)) {
                                            //判断是否连续新增
                                            if (isContinuousNew) {
                                                //重置表单
                                                panel.reset();

                                                //设置焦点
                                                form.down('field').focus(false, 50);
                                            }
                                            else {
                                                //启用工具栏
                                                toolbar.setDisabled(false);

                                                //返回一览标签
                                                card.getLayout().setActiveItem('spms-card-list');

                                                //刷新数据
                                                Refresh();
                                            }
                                        }
                                    },
                                    failure: spms.exception.HandleFailureError
                                }
                            );
                        }
                    }
                }
            }
        );
    </script>
}
